package com.opgea.crm.common.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class DateUtil {
	
public static String dateToString(Date date)

{
	String sdate=null;
	SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
	if(date!=null)
	{
		sdate=sdf.format(date);
	}
	return sdate;
}


public static Date stringToDate(String sdate)

{
	Date date=null;
	SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
	try{
	if(sdate!=null)
	{
		date=sdf.parse(sdate);
	}
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	return date;
}

public static String dateToTime(Date date)
{
	String time=null;
	SimpleDateFormat sdf=new SimpleDateFormat("hh:mm:ss");
	if(date!=null)
	{
		time=sdf.format(date);
	}
	return time;
}

public static String dateDifference(Date completiondate)
{
	if(completiondate!=null)
	{
		Calendar comCalender=Calendar.getInstance();
		comCalender.setTime(completiondate);
		Calendar currentDate=Calendar.getInstance();
		
		long miliseconds=comCalender.getTimeInMillis()-currentDate.getTimeInMillis();
		 long diffDays = miliseconds / (24 * 60 * 60 * 1000);
		return (diffDays!=0)?diffDays+"/days":"0";
	}
	return "0";
}
public static void main(String[] args) {
	System.out.println(dateDifference(stringToDate("2011-09-02")));
}
}
	

